<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

/**
 * TYPOlight webCMS
 *
 * The TYPOlight webCMS is an accessible web content management system that 
 * specializes in accessibility and generates W3C-compliant HTML code. It 
 * provides a wide range of functionality to develop professional websites 
 * including a built-in search engine, form generator, file and user manager, 
 * CSS engine, multi-language support and many more. For more information and 
 * additional TYPOlight applications like the TYPOlight MVC Framework please 
 * visit the project website http://www.typolight.org.
 *
 * This file modifies the data container array of table tl_module.
 *
 * PHP version 5
 * @copyright  Martin Komara 2007 
 * @author     Martin Komara 
 * @package    Catalog 
 * @license    GPL 
 * @filesource
 */

$GLOBALS['TL_DCA']['tl_module']['palettes']['catalogListing'] = &$GLOBALS['TL_DCA']['tl_module']['palettes']['listing'];
$GLOBALS['TL_DCA']['tl_module']['palettes']['catalogtoday'] = '{title_legend},name,headline,type;{config_legend},catalog_discount_product;{protected_legend:hide},protected;{expert_legend:hide},guests,cssID,space';

/**
 * Add fields to tl_module
 */
$GLOBALS['TL_DCA']['tl_module']['fields']['catalog_discount_product'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_module']['catalog_discount_product'],
	'exclude'                 => true,
	'inputType'               => 'select',
	'options_callback'        => array('tl_module_catalogs', 'getDiscountProducts'),
	'eval'                    => array('multiple'=>false, 'mandatory'=>true)
);

/**
 * Class tl_module_catalogs
 *
 * Provide miscellaneous methods that are used by the data configuration array.
 * @copyright  Billy Song 2010
 * @author     Billy Song <songbin_82@hotmail.com>
 * @package    Controller
 */
class tl_module_catalogs extends Backend
{

	/**
	 * Import the back end user object
	 */
	public function __construct()
	{
		parent::__construct();
		$this->import('BackendUser', 'User');
	}


	/**
	 * Get all news archives and return them as array
	 * @return array
	 */
	public function getDiscountProducts()
	{
		$arrProducts = array();
		$objProducts = $this->Database->execute("SELECT id, name FROM product_catalog ORDER BY pid ASC, name ASC");

		while ($objProducts->next())
		{			
			$arrProducts[$objProducts->id] = $objProducts->name;			
		}

		return $arrProducts;
	}
}

?>